# #!/usr/bin/env python3
# # -*- coding: utf-8 -*-
import pymysql

import sys, os
path = os.path.abspath('../..')+'/ark_project'
sys.path.append(path)  # 会追加到列表最尾部
from settings import mysql_settings
settings=mysql_settings.mysqlSettings()
settings=settings.mysql_conf
MYSQL_HOST=settings['MYSQL_HOST']
MYSQL_PORT=settings['MYSQL_PORT']
MYSQL_DB=settings['MYSQL_DB']
MYSQL_USER=settings['MYSQL_USER']
MYSQL_PASSWD=settings['MYSQL_PASSWD']
MYSQL_CHARTSET=settings['MYSQL_CHARTSET']

db = pymysql.connect(
            host=MYSQL_HOST,
            port=MYSQL_PORT,
            database=MYSQL_DB,
            user=MYSQL_USER,
            password=MYSQL_PASSWD,
            charset=MYSQL_CHARTSET
        )
# 使用cursor()方法获取操作游标
cursor = db.cursor()
#
# import time
# import datetime
# import requests
# import json
# from selenium import webdriver
# from selenium.webdriver.chrome.options import Options
#
# chrome_options = Options()  # 模拟器设置
# chrome_options.add_argument('start-maximized')  # 指定浏览器分辨率
# chrome_options.add_argument('--disable-gpu')  # 谷歌文档提到需要加上这个属性来规避bug
# chrome_options.add_argument('--hide-scrollbars')  # 隐藏滚动条, 应对一些特殊页面
# chrome_options.add_argument('blink-settings=imagesEnabled=false')  # 不加载图片, 提升速度
# chrome_options.add_argument('-headless')   #无界面设置
# chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
# chrome_options.add_experimental_option('useAutomationExtension', False)
# chrome_options.add_argument('--ignore-certificate-errors')
# chrome_options.add_argument("user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36")
# # driver=webdriver.Chrome(r'C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe')
# driver = webdriver.Chrome(chrome_options=chrome_options,executable_path='C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe')
# #/usr/local/bin/chromedriver
# # driver = webdriver.Chrome(chrome_options=chrome_options,executable_path='/usr/local/bin/chromedriver')

#
#
# web='nasdaq'
# ark_type='ARKF'
# today_date=str(datetime.datetime.today().date())
# url='https://api.nasdaq.com/api/quote/ARKX/historical?assetclass=stocks&fromdate=2021-05-03&limit=18&todate='+today_date
# # print(url)
# # headers = {
# #             "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36"}
# # text = requests.get(url=url, headers=headers).content.decode('utf-8')
#
# driver.get(url)
#
# datas=driver.find_element_by_tag_name('pre').text
# print(driver.page_source)
# print(datas)
# json_data=json.loads(datas)
# row_data=json_data['data']['tradesTable']['rows']
# date_closevalue_dict={}
# print(row_data)
# print('======')
# for each_data in row_data:
#     date = each_data['date']
#     new_date = str(datetime.datetime.strptime(date, '%m/%d/%Y').date())
#     close_value = each_data['close']
#     date_closevalue_dict[new_date]=close_value
#
#
# driver.quit()
#
# # date='06/02/2021'
# # new_date=datetime.datetime.strptime(date,'%m/%d/%Y').date()
# # print(new_date)
# # ark_type='ARKG'
# # sql_select="select %s from ark_fundvaluecashintout where date='%s'"%(ark_type+'_close',new_date)
# # print(sql_select)
# # cursor.execute(sql_select)
# # select_res=cursor.fetchone()[0]
# # if select_res is None:
# #     print('--',None)
#
# import os
import json
import datetime
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

# chrome_options = Options()  # 模拟器设置
# chrome_options.add_argument('start-maximized')  # 指定浏览器分辨率
# chrome_options.add_argument('--disable-gpu')  # 谷歌文档提到需要加上这个属性来规避bug
# chrome_options.add_argument('--hide-scrollbars')  # 隐藏滚动条, 应对一些特殊页面
# chrome_options.add_argument('blink-settings=imagesEnabled=false')  # 不加载图片, 提升速度
# chrome_options.add_argument('-headless')  # 无界面设置
# chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
# chrome_options.add_experimental_option('useAutomationExtension', False)
# chrome_options.add_argument('--ignore-certificate-errors')
# chrome_options.add_argument(
# "user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36")
# driver = webdriver.Chrome(chrome_options=chrome_options,
#                         executable_path='C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe')
# ark_fundflow_html_path=''


def read_datas(datas_str):
    json_data = json.loads(datas_str)
    row_data = json_data['data']['tradesTable']['rows']
    date_closevalue_dict = {}
    for each_data in row_data:
        date = each_data['date']
        new_date = str(datetime.datetime.strptime(date, '%m/%d/%Y').date())
        close_value = each_data['close'].replace('$', '')
        date_closevalue_dict[new_date] = close_value
        print(each_data)

import os
import re
if __name__=='__main__':
    # a = [datetime.date(2010, 10, 20), 1, 4, datetime.date(2013, 10, 20)]
    start_date_str='2021-06-17'
    ark_fundflow_html_path='fundflow_html/'
    ark_fundflow_html_files = os.listdir(ark_fundflow_html_path)
    ark_type=['arkf', 'arkg', 'arkk', 'arkq', 'arkw', 'arkx', 'izrl', 'prnt']

    etfdb_html_files_today_ark_type=[]
    nasdaq_html_files_today_ark_type=[]
    for file in ark_fundflow_html_files:
        if re.findall(start_date_str,file):
            if re.findall('etfdb',file):
                etfdb_html_files_today_ark_type.append(file[6:10])
            elif re.findall('nasdaq',file):
                nasdaq_html_files_today_ark_type.append(file[7:11])

    print(len(ark_fundflow_html_files),ark_fundflow_html_files)
    print(len(etfdb_html_files_today_ark_type),etfdb_html_files_today_ark_type)
    print(len(nasdaq_html_files_today_ark_type), nasdaq_html_files_today_ark_type)

    test_type=[ 'arkf', 'arkg', 'arkk', 'arkq', 'arkw', 'arkx', 'izrl', 'prnt']
    print(list(set(ark_type)-set(test_type)))

    print(list(set(test_type) - set(ark_type)))